package com.bootdo.program.wallpaper.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.program.wallpaper.dao.ReportDataDao;
import com.bootdo.program.wallpaper.domain.BzDeductionRecordDO;
import com.bootdo.program.wallpaper.service.BzDeductionRecordService;
import com.bootdo.program.wallpaper.vo.ReportVo;
import com.google.common.collect.Lists;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author guoyunfei on 2022/3/1 13:39
 * @className ReportDataController
 * @description TODO
 * @Version 1.0
 */

@Controller
@RequestMapping("/wallpaper/report")
public class ReportDataController {

    @Autowired
    private ReportDataDao reportDataDao;

    @Autowired
    private BzDeductionRecordService bzDeductionRecordService;

    @GetMapping("/deductionRecordPage")
    @RequiresPermissions("wallpaper:report:deductionRecordPage")
    public String deductionRecordReport(@RequestParam Map<String, Object> params){
        return "wallpaper/report/deductionRecordReport";
    }

    @ResponseBody
    @GetMapping("/deductionRecordList")
    @RequiresPermissions("wallpaper:report:deductionRecordPage")
    public R BzDeductionRecord(@RequestParam Map<String, Object> params){
        Map<String,Object> result = new HashMap<>();

        List<BzDeductionRecordDO> list = reportDataDao.list(params);

        List<Integer> downTotal = Lists.newArrayList();
        List<Integer> deTotal = Lists.newArrayList();
        for (int i = 0; i < list.size(); i++) {
            downTotal.add(list.get(i).getSumCount());
            deTotal.add(list.get(i).getDeCount());
        }
        result.put("downTotal",downTotal);
        result.put("deTotal",deTotal);

        return R.ok(result);
    }


    @GetMapping("/userReport")
    @RequiresPermissions("wallpaper:report:userReport")
    public String userPage(@RequestParam Map<String, Object> params){
        return "wallpaper/report/userReport";
    }

    @ResponseBody
    @GetMapping("/userCount")
    @RequiresPermissions("wallpaper:report:userReport")
    public R userCount(){
        Map<String,Object> result = new HashMap<>();

        List<Integer> userCount = reportDataDao.getUserCount();
        result.put("userCount",userCount);

        List<Integer> talentCount = reportDataDao.getTalentCount();
        result.put("talentCount",talentCount);

        return R.ok(result);
    }

}
